package converter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import domain.Purchase;

import repository.PurchaseRepository;

@Component
public class PurchaseConverter implements Converter<String, Purchase>{

	private PurchaseRepository purchaseRepository;

	@Autowired
	public PurchaseConverter(PurchaseRepository purchaseRepository) {
		this.purchaseRepository = purchaseRepository;
	}

	@Override
	public Purchase convert(String source) {
		return purchaseRepository.getPurchase(Integer.valueOf(source));
	}
}
